/**
 * Created by huangxuehua on 2017/11/27.
 */
//$("header>a.goBack").click(function(){
//    window.history.back()
//});
var toastLoading = new auiToast({});
var dialog = new auiDialog();
var xpHome = new Vue({
    el: '#app',
    data: {
        imgBaseUrl: nUrls.imgBaseUrl,//图片路径
        goodsIndentInfo: {},//商品订单信息
        orderStatusDetail:{lastTraces:""},//订单状态详情
        orderStatusDesc:"",//订单状态页面描述
        countMoney: 0,//总金额
        tuijianrenInfo:[],//推荐人
        invoice:{},//发票信息
    },
    methods: {
        getImage: function (url) {
            if (url) {
                return xpHome.imgBaseUrl + url;
            }
        },
        dateTime:function(time){
            return nUtils.dateTimeDetail(time);
        },
        InitData: function () {
            var IndentInfo = window.localStorage.getItem("IndentGoodsDetail");//接收订单页面信息
            if (IndentInfo) {
                xpHome.goodsIndentInfo = JSON.parse(IndentInfo);
                xpHome.invoice= xpHome.goodsIndentInfo.Invoice;//获得发票信息
                //console.log("--xpHome.goodsIndentInfo-.",xpHome.goodsIndentInfo);
                xpHome.countMoneyFun();
            }
         },
        countMoneyFun: function(){   //商品总价
                var temp = xpHome.goodsIndentInfo;
                 console.log("+++",xpHome.goodsIndentInfo);
                var tempChildren = temp.children;

            var beforeUserInfo = "";// 推荐人信息添加
            var userInfo = {isOneUser:true,oneUserName:"",refereName:[]};// 推荐人信息添加

            for (var i = 0;i< tempChildren.length;i++) {//循环订单中的物品
                    xpHome.countMoney += tempChildren[i].shop_price * tempChildren[i].goods_number;

                if(i==0){ //推荐人信息添加
                    beforeUserInfo = temp.children[i].refere_name;
                }
                userInfo.oneUserName = temp.children[i].refere_name;
                userInfo.refereName.push(userInfo.oneUserName);
                if(beforeUserInfo!= temp.children[i].refere_name){
                    userInfo.isOneUser = false;
                }
                }
            xpHome.tuijianrenInfo.push(userInfo);
        },
        getTypeAndColor:function(target,type){   //分割字符串
            var temp = "";
            if(target){
                var arr = target.split("-----");
                if(arr.length == 2){
                    if(type == 0){//颜色
                        return arr[1];
                    }else{//型号
                        return arr[0];
                    }
                }
            }
            return temp;
        },
        goAfterSale:function(idx){  //申请售后
            window.localStorage.setItem("afterSaleInfo",JSON.stringify(xpHome.goodsIndentInfo.children[idx]))
                    //console.log("--xpHome.goodsIndentInfo--",xpHome.goodsIndentInfo.children[idx])
            window.location.href="../my_center_detail/after_sale.html"
        },
        getOrderStatusInfo:function(){ //获取订单状态详情
            toastLoading.loading({
                title:"数据加载中",
            },function(ret){
            });
            var data={
                "data[order_id]":xpHome.goodsIndentInfo.order_id
            }
            $.ajax({
                url:nUrls.getOrderStatusDetailURL,
                type:"POST",
                data:data,
                success: function (data) {
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.orderStatusDetail=result.data;
                        xpHome.orderStatusDesc = xpHome.getOrderStatusDetail(xpHome.goodsIndentInfo.order_status);
                        toastLoading.hide();
                    }
                },
                error: function () {
                    console.log("获取信息出错");
                    toastLoading.hide();
                }
            })
        },
        getOrderStatusDetail:function(order){//根据 状态获取 订单详情名称
            var status = "";
            switch (order) {
                case "0":
                    status = "您尚未支付,请先付款";
                    break;
                case "1":
                    status = "尚未发货,暂没物流信息";
                    break;
                case "2"://
                    status =xpHome.orderStatusDetail.lastTraces.AcceptStation ;
                    break;
                case "3"://
                    status =xpHome.orderStatusDetail.lastTraces.AcceptStation ;
                    break;
                case "4"://
                    status =xpHome.orderStatusDetail.lastTraces.AcceptStation ;
                    break;
            }
            return status;
        } ,
        goWuliu:function(orderId){
            window.location.href="../my_center_detail/wuliu.html?orderId="+orderId;
            //console.log("--xpHome.goodsIndentInfo.order_id--",xpHome.goodsIndentInfo.order_id)
        },
        getOrderStatus:function(order){//根据 num 获取 订单状态名称
            var status = "";
            switch (order){
                case "0":
                    status = "尚未支付";
                    break;
                case "1":
                    status = "待发货";
                    break;
                case "2"://
                    status = "待收货";
                    break;
                case "3"://
                    status = "待评价";
                    break;
                case "4"://
                    status = "已评价";
                    break;

            }
            return status;
        } ,
        getFaHuoStatus:function(order){//根据 num 获取 订单状态名称
            var status = "";
            switch (order){
                case "2"://
                    status = "申请售后";
                    break;
                case "3"://
                    status = "申请售后";
                    break;
                case "4"://
                    status = "申请售后";
                    break;
            }
            return status;
        } ,
        goGoodsDetail:function(goods_id){
           window.location.href="../detail/goods_detail.html?id="+goods_id;
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        },
        showTel:function(type){
            if (type == 1) {
                dialog.alert({
                    title: "温馨提示",
                    msg: '小普客服  400-152-8518',
                    buttons: ['关闭']
                }, function (ret) {
                    console.log(ret)
                })
            } else {
                dialog.alert({
                    title: "温馨提示",
                    msg: '小普客服  400-152-8518',
                    buttons: ['关闭']
                }, function (ret) {
                    console.log(ret)
                })
            }
        }
    }
});
$(function(){
    xpHome.InitData();
    xpHome.getOrderStatusInfo();

    var btns = document.querySelectorAll('.copyBtn');
    var clipboard = new Clipboard(btns);

    clipboard.on('success', function(e) {
        var toast = new auiToast(); //初始化toast事件
        toast.custom({
            title: "复制成功",
            html: '',
            duration: 2000
        })
    });
    clipboard.on('error', function(e) {
        var toast = new auiToast(); //初始化toast事件
        toast.custom({
            title: "复制失败",
            html: '',
            duration: 2000
        })
    });
});

